package com.ttai.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.igexin.sdk.PushManager;
import com.ttai.R;
import com.ttai.dagger.componet.activity.DaggerVerifyMiYaoComponet;
import com.ttai.dagger.module.activity.VerifyMiYaoPresenterModule;
import com.ttai.presenter.activity.InsertIdAcountPresenter;
import com.ttai.presenter.activity.InsertNewAcountPresenter;
import com.ttai.presenter.activity.InsertTipAcountPresenter;
import com.ttai.presenter.activity.VerifyMiYaoPresenter;
import com.ttai.ui.base.BaseActivity;
import com.ttai.untils.Constant;
import com.ttai.untils.getui.DemoIntentService;

import javax.inject.Inject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class VerifyMiYao extends BaseActivity {

    @Inject
    VerifyMiYaoPresenter verifyMiYaoPresenter;

    @Bind(R.id.detail_title)
    TextView detailTitle;
    @Bind(R.id.et_verifymiyao)
    EditText etVerifymiyao;
    @Bind(R.id.btn_verifymiyao)
    Button btnVerifymiyao;
    private String secretKey;

//    private InsertNewAcountPresenter insertNewAcountPresenter;
//    private InsertIdAcountPresenter insertIdAcountPresenter;
//    private InsertTipAcountPresenter insertTipAcountPresenter;
//    private String token;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_verifymiyao);
        ButterKnife.bind(this);
        setComponet();

//        insertNewAcountPresenter = new InsertNewAcountPresenter();
//        insertTipAcountPresenter = new InsertTipAcountPresenter();
//        insertIdAcountPresenter = new InsertIdAcountPresenter();

    }

    @Override
    public void next(View view) {

    }

    @Override
    public void pre(View view) {

    }

    @Override
    public void setComponet() {
        DaggerVerifyMiYaoComponet.builder()
                .verifyMiYaoPresenterModule(new VerifyMiYaoPresenterModule(this))
                .build()
                .in(this);
    }

    @OnClick(R.id.btn_verifymiyao)
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_verifymiyao:
                String token = EnterPage.enterphonenumber;
                String key = etVerifymiyao.getText().toString();
                secretKey = Constant.shaEncrypt(key);
                String clientId = PushManager.getInstance().getClientid(VerifyMiYao.this);
                Log.i("55", "onViewClicked: "+verifyMiYaoPresenter.acount);
                System.out.println("cid:"+clientId+" key:"+secretKey+" token:"+token);
                if (verifyMiYaoPresenter.acount < 3){
                    verifyMiYaoPresenter.verifyMiyao1(clientId,secretKey,token);
                    etVerifymiyao.setText("");
                    etVerifymiyao.setFocusable(true);
                }else {
                    this.finish();
                    Intent intent = new Intent(VerifyMiYao.this, EnterPage.class);
                    startActivity(intent);
                }
                break;
        }
    }

//    public void storeNewAcount() {
//        token = Constant.getToken();
//        insertNewAcountPresenter.storeNewAcount(token);
//    }
//
//    public void storeTipAcount() {
//        token = Constant.getToken();
//        insertTipAcountPresenter.storeTipAcount(token);
//    }
//
//    public void restoreIdAcount() {
//        token = Constant.getToken();
//        insertIdAcountPresenter.storeIdAcount(token);
//    }
}
